package com.atos.smp.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import net.codeissue.web.common.ServiceFinder;

import com.atos.smp.beans.Collaborator;
import com.atos.smp.business.impl.CollaboratorManagerImpl;
import com.atos.smp.dao.CollaboratorDao;

public class CollaboratorConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1,
			String submittedValue) {
		if (submittedValue.trim().equals("")) {
			return null;
		} else {
			CollaboratorDao dao = (CollaboratorDao) ServiceFinder
					.findBean("collaboratorDao");
			CollaboratorManagerImpl cm = new CollaboratorManagerImpl(dao);
			Collaborator c = cm.findCollaboratorByDas(submittedValue);
			return c;

		}

	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		if (value == null || value.equals(""))
			return "";
		else
			return value.toString();
	}

}
